class Solution(object):
    def maxSubarraySumCircular(self, nums):
        now_max = - float('inf')
        now_min = float('inf')
        total = sum(nums)
        n = len(nums)
        now_max_count = - float('inf')
        now_min_count = float('inf')
        for num in nums:
            now_max_count = max(now_max_count + num, num)
            now_min_count = min(now_min_count + num, num)
            now_max = max(now_max, now_max_count)
            now_min = min(now_min, now_min_count)
        if total == now_min:
            return now_max
        else:
            return max(now_max, total - now_min)





data = Solution()
nums = [1, -2, 3, -2]
print(data.maxSubarraySumCircular(nums))
